#!/bin/bash

ROOT_PATH=`cd $(dirname $0) && pwd`
SCRIPT_NAME=`basename $0`
SCRIPT=$ROOT_PATH/`basename $0`
cd ${ROOT_PATH}/softwares/OpenCAEPoro/debug

. /usr/share/modules/init/bash
module use /opt/intel/modulefiles
module use /opt/nvidia/hpc_sdk/modulefiles
module use /opt/modulefiles
module use ${ROOT_PATH}/env

module purge
module load icc/2023.1.0
module load openmpi/4.1.6-mlnxofed-cuda12.3-gdrcopy-full
module load nvhpc-nompi/23.11
module load mkl/2023.1.0
module load cmake/3.22

# Load hypre / parmetis / petsc
module load hypre/2.28.0/debug parmetis/4.0.3/debug petsc/3.19.3/debug

export OMP_NUM_THREADS=2
export OMP_PROC_BIND=true
export OMP_PLACES=cores

log_t=`date "+%Y%m%d-%H%M%S"`

mkdir -p logs/${log_t}

touch logs/${log_t}/start.sh
cat $SCRIPT > logs/${log_t}/start.sh

mpirun -H 198.19.19.254:20,198.19.19.205:20 -np 40 -report-bindings --map-by ppr:10:numa:pe=2 --bind-to core --x OMP_NUM_THREADS --x OMP_PROC_BIND --x OMP_PLACES --x PATH --x LD_LIBRARY_PATH ./testOpenCAEPoro ./data/case1/case1.data verbose=1 2>&1 | tee logs/${log_t}/run.log

mv ./data/case1/FastReview.out logs/${log_t}/
mv ./data/case1/statistics.out logs/${log_t}/
mv ./data/case1/SUMMARY.out logs/${log_t}/